package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Experience;
import cn.wolfcode.crm.service.IExperienceService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("experience")
public class ExperienceController {

    @Autowired
    private IExperienceService experienceService;

    @RequestMapping("")
    public String index(){
        return "basic/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public List<Experience> list(){
        return experienceService.listAll();
    }

    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Experience experience){

        JsonResult result = new JsonResult();
        try {
            experienceService.save(experience);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Experience experience){

        JsonResult result = new JsonResult();
        try {
            experienceService.update(experience);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("编辑操作失败");
        }
        return result;
    }

    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        JsonResult result = new JsonResult();
        try {
            experienceService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return result;
    }
}
